package icu.lookyousmileface.threadpool;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author starrysky
 * @title: CacheThreadPool
 * @projectName Juc_Pro
 * @description: 缓存池，可伸缩，遇强则强，遇弱则弱
 * @date 2021/1/2910:19 下午
 */
public class CacheThreadPool {
    public static void main(String[] args) {
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();

        try {
            for (int i = 1; i <= 50; i++) {
                cachedThreadPool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"=>ok");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        cachedThreadPool.shutdown();
        }
    }
}
